package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Pagination;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.Subject;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/students")
public class StudentsController {
    @Autowired
    private StudentsService studentsService;


    /**
     * 分页查询
     * @param clazzPage
     * @return
     */
    @GetMapping
    public Result list(Pagination clazzPage){
    PageResult pageResult = studentsService.list(clazzPage);
        return Result.success(pageResult);

    }

    /**
     * 删除学员
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result delect(@PathVariable List<Integer> ids){
        log.info("删除部门，id为：{}",ids);
        studentsService.dept(ids);
        return Result.success();
    }

    /**
     * 添加学员
     * @param student
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Student  student){
        log.info("添加学员，员工信息：{}",student);
        studentsService.add(student);
        return Result.success();
    }

    /**
     * 主键ID查询学员的信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result listid(@PathVariable Integer id){
        log.info("查询学员，id为：{}",id);
       Student  student =studentsService.listid(id);
        return Result.success(student);
    }

    /**
     * 修改学员
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Student student ){
        log.info("修改员工信息，参数：{}",student);
        studentsService.udete(student);
        return Result.success();

    }

    /**
     * 添加学员的违纪信息
     * @param id
     * @param score
     * @return
     */
    @PutMapping("/violation/{id}/{score}")
    public Result vioStudent(@PathVariable Integer id,@PathVariable Short score){
        log.info("修改员工信息，参数：{},{}",id,score);
        studentsService.undatevs(id,score);
        return Result.success();

    }





}
